package com.wonders.cyxtjsonupdate.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @Description:
 * @ClassName: DataSourceConfig
 * @Author: 陈兆庆
 * @Date: 2021/12/29 17:38
 * @Version: 1.0     // 版本
 */
@Configuration
public class DataSourceConfig {

    /*    @Bean(name = "primaryDataSource")
        @Primary
        @Qualifier("primaryDataSource")
        @ConfigurationProperties(prefix="spring.datasource.ds1")
        public DataSource primaryDataSource() {
            return DataSourceBuilder.create().build();
        }

        @Bean(name = "secondaryDataSource")
        @Qualifier("secondaryDataSource")
        @ConfigurationProperties(prefix="spring.datasource.ds2")
        public DataSource secondaryDataSource() {
            return DataSourceBuilder.create().build();
        }

        @Bean(name="primaryJdbcTemplate")
        public JdbcTemplate primaryJdbcTemplate (@Qualifier("primaryDataSource")  DataSource dataSource ) {
            return new JdbcTemplate(dataSource);
        }

        @Bean(name="secondaryJdbcTemplate")
        public JdbcTemplate  secondaryJdbcTemplate(@Qualifier("secondaryDataSource") DataSource dataSource) {
            return new JdbcTemplate(dataSource);
        }*/
        /*    @Bean(name = "primaryDataSource")
        @Primary
        @Qualifier("primaryDataSource")
        @ConfigurationProperties(prefix = "spring.datasource.ds1")
        public DataSource primaryDataSource() {
            return DataSourceBuilder.create().build();
        }

        @Bean(name = "secondaryDataSource")
        @Qualifier("secondaryDataSource")
        @ConfigurationProperties(prefix = "spring.datasource.ds2")
        public DataSource secondaryDataSource() {
            return DataSourceBuilder.create().build();
        }

        @Bean(name = "thirdDataSource")
        @Qualifier("thirdDataSource")
        @ConfigurationProperties(prefix = "spring.datasource.ds3")
        public DataSource thirdDataSource() {
            return DataSourceBuilder.create().build();
        }


        @Bean(name = "primaryJdbcTemplate")
        @Primary
        public JdbcTemplate primaryJdbcTemplate(@Qualifier("primaryDataSource") DataSource dataSource) {
            return new JdbcTemplate(dataSource);
        }

        @Bean(name = "secondaryJdbcTemplate")
        public JdbcTemplate secondaryJdbcTemplate(@Qualifier("secondaryDataSource") DataSource dataSource) {
            return new JdbcTemplate(dataSource);
        }

        @Bean(name = "thirdJdbcTemplate")
        public JdbcTemplate thirdJdbcTemplate(@Qualifier("thirdDataSource") DataSource dataSource) {
            return new JdbcTemplate(dataSource);
        }*/
    @Bean(name = "primaryDataSource")
    @Primary
    @Qualifier("primaryDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.ds1")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "secondaryDataSource")
    @Qualifier("secondaryDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.ds2")
    public DataSource secondaryDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "thirdDataSource")
    @Qualifier("thirdDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.ds3")
    public DataSource thirdDataSource() {
        return DataSourceBuilder.create().build();
    }


    @Bean(name = "primaryJdbcTemplate")
    @Primary
    public JdbcTemplate primaryJdbcTemplate(@Qualifier("primaryDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "secondaryJdbcTemplate")
    public JdbcTemplate secondaryJdbcTemplate(@Qualifier("secondaryDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "thirdJdbcTemplate")
    public JdbcTemplate thirdJdbcTemplate(@Qualifier("thirdDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }


}
